package com.briup.estore.adminAPI.web.controller;

import com.briup.estore.common.bean.Order;
import com.briup.estore.common.service.IOrderService;
import com.briup.estore.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;


/**
 * @author adam
 * @date 2022/10/18
 */
@RestController
@CrossOrigin
@RequestMapping("/order")
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
   private IOrderService orderService;

    @GetMapping("getOrderInfo")
    @ApiOperation("订单信息筛选")
    public Result getOrderInfo(@RequestParam(required = false, defaultValue = "") String orderId, @RequestParam(required = false, defaultValue = "") String status, Integer pageSize, Integer pageNum) {
        try {
            Page<Order> page = orderService.findOrders(orderId, status, pageSize, pageNum);
            return Result.success(page);
        } catch (Exception e) {
            return Result.error(80000, e.getMessage());
        }

    }

    @PostMapping(value = "/updateOrder")
    @ApiOperation("订单修改")
    public Result updateOrder(@RequestBody Order order) {

        try {
            orderService.updateOrder(order);
            return Result.success();
        } catch (Exception e) {
            return Result.error(50000, e.getMessage());
        }

    }

    @GetMapping("getOrder/{id}")
    public Result getOrder(@PathVariable String id) {
        Order order = null;
        try {
            order = orderService.findOrderById(id);
            return Result.success(order);
        } catch (Exception e) {
            return Result.error(50000, e.getMessage());
        }

    }

}
